import 'cube.css/src/scss/neat.scss'
import 'static/font/iconfont.css'
import 'element-ui/lib/theme-default/index.css'
import './set.scss'
import Vue from 'vue'
import ElementUI from 'element-ui'
import UnifyHeader from 'components/header/header.vue'
import UnifyFooter from 'components/footer/footer.vue'
import Suspension from 'components/suspension/suspension'
import mixins from '@/mixins'
import Utils from '../../components/component/util'
import Api from '../../api.js'
import {DEVELOPMENT, PRODUCTION} from "../../config"

let apiHost = process.env.NODE_ENV === 'development' ? DEVELOPMENT : PRODUCTION

Vue.mixin(mixins)
Vue.use(ElementUI)
Vue.use(Utils)  // 工具函数
let bbsSlsectDate = {}

//eslint-disable-next-line no-new
new Vue({
  el: '#app',
  data: {
    showSuspensionHeight: 0,
    picturePrefix: `http://${apiHost.IMAGE_API_HOST}/`,
    attributes: '',
    nowSize: '',
    nowColor: '',
    skuCode: '',
    price: 0
  },
  methods: {
    startCustom() {
      if (localStorage.getItem("userDbId")) {
        location.href = '/album/hejiEdit'
      } else {
        this.setUrlCallback()
      }
    },
    /*更新sku*/
    updataSkuData() {
      this.skuCode = `${this.getFromSession("category")}.${this.nowSize}`
      Api.sku.querySku({
        category: this.getFromSession("category"),
        parameter: this.skuCode
      }).then(res => {
        bbsSlsectDate.tplCode = res.data.templateCode
        bbsSlsectDate.skuId = res.data.skuId
        bbsSlsectDate.price = res.data.price
        this.price = res.data.price
        bbsSlsectDate.category = res.data.category
        bbsSlsectDate.editCnfName = "pc_heji_500X350_10_single"
        setTimeout(function () {
          sessionStorage.setItem("bbsSlsectDate", JSON.stringify(bbsSlsectDate))
        }, 100)
      })
    },
    _setSessionStorageData: function () {
      sessionStorage['urlQuery'] = JSON.stringify({
        'category': this.getQueryString('category', 'heji'),
        'defDbId': this.getQueryString("defDbId", '5ea5e91b-21fd-481f-ab11-c767b19eed53'),
        'tplCode': this.getQueryString("tplCode", 'pc_heji_500X350_10')
      })
      sessionStorage['titleName'] = '合集'
    },
    _getAttributes: function () {
      Api.sku.queryAttributes({category: this.getFromSession("category")}).then(res => {
        if (!res) {
          return
        }
        let attributeValues = res.data.attributes
        bbsSlsectDate.name = res.data.name + '.' + attributeValues[0].attributeValues[0].name + '.' + attributeValues[1].attributeValues[0].name
        bbsSlsectDate.skuCode = res.data.code + '.' + attributeValues[0].attributeValues[0].code + '.' + attributeValues[1].attributeValues[0].code
        bbsSlsectDate.size = attributeValues[0].attributeValues[0].code
        this.nowSize = bbsSlsectDate.skuCode
        this.updataSkuData()
      })
    }
  },
  mounted() {
    this._setSessionStorageData()
    this._getAttributes()
    let that = this
    this.$nextTick(function () {
      that.showSuspensionHeight = that.$refs.showSuspensionFlag.offsetTop
    })
  },
  created: function () {
    this.checkWebpFeature('lossy', function (feature, isSupport) {
      if (isSupport) {
        require('./background-webp.scss')
      } else {
        require('./background-png.scss')
      }
    })
    document.body.style.cssText = 'opacity:1;'
  },
  components: {
    UnifyHeader,
    UnifyFooter,
    Suspension
  }
})
